package com.abc.robot01.room.dao

import androidx.room.Dao
import androidx.room.Insert
import androidx.room.Query
import com.abc.robot01.room.bean.ChatAnswerBean
import java.sql.SQLException

@Dao
interface ChatAnswerDao {

    /**
     * 增
     *
     * @throws SQLException
     */
    @Insert
    fun addAnswer(answer: ChatAnswerBean): Long

    /**
     * 查询所有答案
     *
     * @return
     */
    @Query("SELECT * FROM CHAT_ANSWER")
    fun qryAllAnswer(): List<ChatAnswerBean>

    /**
     * 按cmd_id分组查询所有答案
     *
     * @return
     */
    @Query("SELECT * FROM CHAT_ANSWER GROUP BY cmd_Id")
    fun qryCustomAnswer(): List<ChatAnswerBean>


    // Update the question and date fields by id
    @Query("UPDATE CHAT_ANSWER SET ttsText = :newAnswer, data = :newDate WHERE id = :id")
    fun updateAnswerById(id: Int, newAnswer: String, newDate: String)

    /**
     * 查询所有答案
     *
     * @return
     */
    @Query("SELECT * FROM CHAT_ANSWER WHERE cmd_id = :cmdId AND type = 0 limit 1")
    fun qryCustomAnswerByCmdId(cmdId: String): ChatAnswerBean

    /**
     * 删除单个答案
     */
    @Query("DELETE FROM CHAT_ANSWER WHERE cmd_id=:cmd")
    fun deleteAnswer(cmd: String): Int

    /**
     * 删 where是删除的条件
     * @author Liu.Heng
     */
    @Query("DELETE FROM CHAT_ANSWER WHERE cmd_id=:cmd")
    fun deleteByCmdId(cmd: String): Int

    /**
     * 查 根据cmd查询数据
     */
    @Query("select * from chat_answer where cmd_id = :cmd_id")
    fun queryAnswerByCmdId(cmd_id: String): List<ChatAnswerBean>

}